package com.oa.hyperion.api.v1;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.oa.hyperion.entity.Role;
import com.oa.hyperion.service.PostRoleService;
import com.oa.hyperion.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Liu
 * @date 2022年01月18日 15:58
 */
@RestController
@RequestMapping("v1/roles")
@Api(tags = "rbac相关接口")
public class RoleController {
    private final RoleService roleService;
    private final PostRoleService postRoleService;
    public RoleController(RoleService roleService, PostRoleService postRoleService) {
        this.roleService = roleService;
        this.postRoleService = postRoleService;
    }

    @GetMapping
    @ApiOperation("获取所有的权限")
    public List<Role> getAllRoles() {
        return roleService.list(new QueryWrapper<Role>().eq("status","y"));
    }


    @GetMapping("by/post/{id}")
    @ApiOperation("获取岗位的角色")
    public List<Role> getPostRole(@PathVariable Integer id) {
        return postRoleService.findRoleByPost(id);
    }

    @DeleteMapping("{id}")
    @ApiOperation("逻辑删除角色")
    public String deleteRole(@PathVariable Integer id) {
        roleService.update(new UpdateWrapper<Role>().set("status", "n").eq("id", id));
        return "删除成功";
    }

}
